home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 016a / xtclock2.zip / SETCLOCK.C < prev    next >
C/C++ Source or Header  |  1991-07-30  |  2KB  |  84 lines

  1.  
  2. /*    Program      SETCLOCK                    */
  3. /*    Version         2.0                        */
  4. /*    Compiler     MIX Power C                     */
  5. /*    Author         Gerald M. Vrooman                  */
  6. /*      Date         12/21/89                     */
  7.  
  8. /*         SETCLOCK can be used to initialize most XT clock cards.         */
  9. /*         The Multi I/O card that  this  routine  was designed for        */
  10. /*    uses the following ports:                    */
  11.  
  12. /*        &h242 - Second                        */
  13. /*        &h243 - Minute                        */
  14. /*        &h244 - Hour                        */
  15. /*        &h246 - Day                        */
  16. /*        &h247 - Month                        */
  17. /*        &h249 - Year                        */
  18.  
  19. /*     SETCLOCK can be easily modified for clock cards using        */
  20. /*     different  ports by changing  the arguments used with        */
  21. /*     outportb().                            */
  22.  
  23.     #include <stdio.h>
  24.     #include <dos.h>
  25.  
  26.     main()
  27.     {
  28.          int year,month,day,hour,minute,second;
  29.          char buffer[20];
  30.  
  31.     printf("\nSETCLOCK  Written 1991 by Gerald M. Vrooman\n\n");
  32.  
  33.     /* read in date and time from console */
  34.  
  35.     printf("enter last two digits of year (yy): ");
  36.     gets(buffer);
  37.     year = atoi(buffer);
  38.  
  39.         printf("enter month (mm): ");
  40.     gets(buffer);
  41.     month = atoi(buffer);
  42.  
  43.         printf("enter  day (dd): ");
  44.     gets(buffer);
  45.     day = atoi(buffer);
  46.  
  47.         printf("enter hour (hh): ");
  48.     gets(buffer);
  49.     hour = atoi(buffer);
  50.  
  51.         printf("enter minute (mm): ");
  52.     gets(buffer);
  53.     minute = atoi(buffer);
  54.  
  55.         printf("enter second (ss): ");
  56.     gets(buffer);
  57.     second = atoi(buffer);
  58.  
  59.  
  60.     /* convert date and time to bcd and update clock */
  61.  
  62.      outportb(0x249,intbcd(year));
  63.          outportb(0x247,intbcd(month));
  64.          outportb(0x246,intbcd(day));
  65.          outportb(0x244,intbcd(hour));
  66.          outportb(0x243,intbcd(minute));
  67.          outportb(0x242,intbcd(second));
  68.  
  69.  
  70.     }
  71.  
  72.  
  73.     /* intbcd converts integer to binary coded decimal byte */
  74.  
  75.     char intbcd(intg)
  76.     int intg;
  77.     {
  78.          int high,low;
  79.  
  80.          high = intg / 10;
  81.          low = intg % 10;
  82.          return(high * 16 + low);
  83.     }
  84.